import time

from selenium.webdriver.common.by import By
from zhoukao3.Base import Base
class Page(Base):
    #定位器
    #定位登录
    login_loc=(By.XPATH,'//a[@href="/home/login.html"]')
    #封装页面
    def login(self):
        self.click(self.login_loc)
    #断言文本：会员登录
    dy1_loc=(By.CSS_SELECTOR,'.reg-new')
    def dy1(self):
       return self.text(self.dy1_loc)
    #定位用户名
    username_loc=(By.NAME,'username')
    #封装用户名
    def username(self):
        self.send_keys(self.username_loc,"13681034647")
    #定位密码
    password_loc=(By.NAME,'password')
    #封装密码
    def password(self):
        self.send_keys(self.password_loc,"111111")
    #定位登录按钮
    loginbtn_loc=(By.CLASS_NAME,'finish-btn')
    #封装登录按钮
    def loginbtn(self):
        self.click(self.loginbtn_loc)
    #断言文本：欢迎回来，13681034647
    dy2_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def dy2(self):
      return  self.text(self.dy2_loc)
    #定位首页
    shouye_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    #封装首页
    def shouye(self):
        self.click(self.shouye_loc)
    #定位搜索框
    sousuokuang_loc=(By.XPATH,'/html/body/div[2]/div/div/form/div[1]/input')
    def sousuokuang(self):
        self.send_keys(self.sousuokuang_loc,"豪士小面包")
    #定位搜索图标
    sousuotubiao_loc=(By.CSS_SELECTOR,'.search-input-btn')
    def sousuotubiao(self):
        self.click(self.sousuotubiao_loc)
    #定位商品页面
    shangpin_loc=(By.XPATH,'//img[@src="/uploads/images/20251017/42392b51b2447832a2bf8debf99c6d2e.png"]')
    def shangpin(self):
        self.click(self.shangpin_loc)
    #定位立即购买按钮
    buybtn_loc=(By.ID,'buy-cart')
    def buybtn(self):
        self.click(self.buybtn_loc)
    #定位到店自提
    ziti_loc=(By.XPATH,'//input[@name="store_id"]')
    def ziti(self):
        self.click(self.ziti_loc)
    #定位支付方式
    yuezhifu_loc=(By.XPATH,'/html/body/div[4]/form/div[3]/div[2]/div[1]/label/input')
    def yuezhifu(self):
        self.click(self.yuezhifu_loc)
    #定位下一步
    xiayib_loc=(By.CLASS_NAME,'ask-btn')
    def xiayibu(self):
        self.click(self.xiayib_loc)
    #业务逻辑
    def luoji_A3mallshangpin(self):
        self.open_url('http://10.59.9.12:7001/')
        #隐式等待
        self.driver.implicitly_wait(2)
        self.login()
        print(self.dy1())
        self.username()
        self.password()
        #强制等待
        time.sleep(10)
        self.loginbtn()
        time.sleep(5)
        print(self.dy2())
        self.shouye()
        self.sousuokuang()
        self.sousuotubiao()
        self.shangpin()
        self.buybtn()
        self.ziti()
        self.yuezhifu()
        self.xiayibu()



